package com.example.demospringmybatisplus.controller;

import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demospringmybatisplus.service.NodeService;
import com.example.demospringmybatisplus.vo.NodeVo;

/**
 * NodeController控制层
 *
 * @author huahua
 * @DATE 2024/9/28
 **/
@RestController
public class NodeController {

    @Autowired
    private NodeService nodeService;

    @RequestMapping("getNodeListByName")
    public List<String> getNodeListByName(String name) {
        // 通过sql语句中distinct去重
        return nodeService.getNodeListByName(name);
    }

    @RequestMapping("getNodeSetByName")
    public Set<String> getNodeSetByName(String name) {
        // 通过set集合去重
        return nodeService.getNodeSetByName(name);
    }

    @RequestMapping("getNodeListNoDistinctByName")
    public List<String> getNodeListNoDistinctByName(String name) {
        // 通过xxx.stream().distinct()去重
        return nodeService.getNodeListNoDistinctByName(name);
    }

    @RequestMapping("getNodeListNoEmptyNameByEsn")
    public List<String> getNodeListNoEmptyNameByEsn(String esn) {
        // 通过sql过滤name不为null的值
        List<NodeVo> nodeListNoEmptyNameByEsn = nodeService.getNodeListNoEmptyNameByEsn(esn);
        return nodeListNoEmptyNameByEsn.stream().map(NodeVo::getEsn).collect(Collectors.toList());
    }

    @RequestMapping("getNodeListByEsn")
    public List<String> getNodeListByEsn(String esn) {
        // 通过xxx.stream().filter()过滤name不为null的值
        List<NodeVo> nodeListByEsn = nodeService.getNodeListByEsn(esn);
        return nodeListByEsn.stream().map(NodeVo::getEsn).filter(Objects::nonNull).collect(Collectors.toList());
    }
}
